<template>
  <div class="box">
        <MyMtHeader titleText="产品详情"/>
        <div class="container">
            <div class="product">
                    <div class="radius" @click="collection">
                        <img width="100%" height="100%" src="../../../static/img/collect.png" alt="">
                    </div>
                    <img src="http://10.203.0.101:8081/shopping/resources/upload/2ad834a8448d4d839d9f1f64b6ee8fea.jpg" alt="">
                    <div class="desc">
                        <div class="desc-text">{{commodityText}}</div>
                        <mt-field label="购买数量" v-model="num"></mt-field>
                        <div class="title-text" @click="sheetVisible = !sheetVisible">
                            <mt-cell title="包装" :value="packingClass"></mt-cell>
                        </div>
                    </div>
                    <div class="tabs">
                        <mt-navbar v-model="selected">
                            <mt-tab-item id="1">商品详情</mt-tab-item>
                            <mt-tab-item id="2">商品评论</mt-tab-item>
                        </mt-navbar>

                        <mt-tab-container v-model="selected">
                            <mt-tab-container-item id="1">
                                <div class="tab-item-box-1">
                                    <img width="100%" height="100%" src="http://10.203.0.101:8081/shopping/resources/upload/2ad834a8448d4d839d9f1f64b6ee8fea.jpg" alt="">
                                    <span>寻真水果 山东烟台栖霞红富士苹果16-24个 5kg 新鲜水果1</span>
                                </div>
                            </mt-tab-container-item>
                            <mt-tab-container-item id="2">
                                <div class="tab-item-box-2">
                                    <div class="top">
                                        <div class="tab-item-top-title">用户评价</div>
                                        <div class="top-item" v-for="(item,index) in userCommentList" :key="index">
                                            <div class="user-name-nox">
                                                <span class="user-name">{{item.userName}}</span>
                                                <van-rate color="#ffd21e" :value="item.value" allow-half void-icon="star" void-color="#eee" />
                                            </div>
                                            <div class="user-text">{{item.text}}</div>
                                        </div>
                                    </div>
                                    <div class="footer">
                                        <div class="title">添加评论</div>
                                        <mt-field   placeholder="请输入评论内容" type="textarea" rows="3" v-model="commentText"></mt-field>
                                        <van-rate color="#ffd21e" v-model="value" allow-half void-icon="star" void-color="#eee" />
                                        <mt-button @click="commitComment()" type="primary">提交</mt-button>
                                    </div>
                                </div>
                            </mt-tab-container-item>
                        </mt-tab-container>
                    </div>
            </div>
        </div>
        <div class="footer-bootom">
            <div class="row">
                <div class="row-left">
                    <div class="new-price">￥{{price}}</div>
                    <div class="old-price">￥73.5</div>
                </div>
                <div class="row-middle">
                    <mt-button type="danger" @click="addCart">加入购物车</mt-button>
                </div>
                <div class="row-right">
                    <mt-button type="danger">立即购买</mt-button>
                </div>
            </div>
        </div>
        <mt-actionsheet
        :actions="actions"
        v-model="sheetVisible">
        </mt-actionsheet>
  </div>
</template>

<script>
import { Toast } from 'mint-ui';
import Vue from 'vue'
import MyMtHeader from '../MyMtHeader/MyMtHeader.vue'
export default {
    components: { MyMtHeader },
    data(){
        return {
            price:73.5,
            commodityText:'【海尔】寻真水果 山东烟台栖霞红富士苹果16-24个 5kg 新鲜水果',
            num: 1,
            sheetVisible:false,
            packingClass:'点击切换',
            actions:[
                {
                    name:'很不戳的包装',
                    method : this.getName
                },
                {
                    name:'买到就是赚到',
                    method : this.getName
                },
            ],
            selected:'1',
            userCommentList:[
                {
                    userName:'110',
                    text:'针的很不戳',
                    value:2.5
                },
                {
                    userName:'10086',
                    text:'话费充吗',
                     value:4.5
                },
                {
                    userName:'12306',
                    text:'高铁票买了吗，没买就别回去了',
                    value:5
                }
            ],
            commentText:'',
            value:2.5
        }
    },
    methods:{
        getName(event){
            this.packingClass = event.name
        },
        commitComment(){
            let {value,commentText} = this
            if ( !commentText ) return Toast('评论内容不能为空!');
            this.userCommentList.push({
                userName:'123456',
                text:commentText,
                value
            })
            this.commentText = ''
            Toast('评论成功!')
        },
        collection(){
            Toast('收藏成功!')
        },
        addCart(){

        }
    },
    mounted(){
        console.log(this.$store.state.count)
    }
}
</script>

<style scoped>
.product{
    position: relative;
}
.radius{
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(0,0,0,.5);
    right: 5px;
    top: 10px;
}
.product img{
    width: 100%;
    height: 100%;
}
.desc{
    padding: 10px;
}
.desc >>> .mint-cell-wrapper{
    padding: 0px;
}
.desc >>> .mint-cell-title{
    width: 80px;
}
.title-text >>> .mint-cell-title{
    flex:none;
}
.title-text >>> .mint-cell-wrapper{
    position: relative;
}
.title-text >>> .mint-cell-text{
    position: absolute;
    left: 10px;
}
.title-text >>> .mint-cell-value{
    position:absolute;
    right: 5px
}

.mint-navbar{
    background: #e8e7e754;
}
.tab-item-box-1{
    padding: 20px;
}
.tab-item-box-2{
    display: flex;
    flex-direction: column;
    padding: 20px;
}
.tab-item-top-title{
    margin: 10px 0px;
    font-size: 20px;
    color: #c7416d;
}
.top-item{
    margin: 10px 0;
    text-align: left;
}
.user-name-nox{
    display: flex;
}
.user-name{
    line-height: 24px;
    margin-right: 10px;
    font-size: 14px;
    color: rgb(59, 61, 59);
}
.user-text{
    font-size: 12px;
    color: #888;
}

.footer .title{
    margin: 10px 0px;
    font-size: 20px;
    color: #c7416d;
}

.footer >>> .mint-cell-wrapper{
    padding: 0px;
}
.footer  >>> .mint-field-core{
    resize: none;
    background: #e7e8e861;
}

.row{
    display: flex;
}
.row-left{
    width: 33%;
    background: #e8e7e754;
}
.new-price{
    padding-top: 5px;
    color: #FF5000;
    font-size: 19px;
}
.old-price{
    padding-bottom: 5px;
    text-decoration: line-through;
    font-size: 12px;
    color: #999;
}
.row-middle{
    width: 33%;
}
.row-right{
    width: 33%;
}
.row-middle >>> .mint-button{
    width: 100%;
    height: 100%;
    background: #FF5000;
}
.row-right >>> .mint-button{
    width: 100%;
    height: 100%;

    background: #1aad19;
}
</style>